package com.wangjiyuan.giftshuo.ui.fragment.listtop.other;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.base.BaseFragment;
import com.wangjiyuan.giftshuo.bean.listtopbean.commentbean.CommentBean;
import com.wangjiyuan.giftshuo.bean.listtopbean.everydaybean.EveryDayBean;
import com.wangjiyuan.giftshuo.bean.listtopbean.maybelikebean.MayBeLikeBean;
import com.wangjiyuan.giftshuo.bean.listtopbean.singleproductbean.SingleProductBean;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.adapter.CommentRecyclerViewAdapter;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.message.UrlMessage;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class CommentFragment extends BaseFragment implements ListTopContract.IListTopView{

    private RecyclerView rv_comment_talk;
    private CommentRecyclerViewAdapter commentRecyclerViewAdapter;
    private List<Object> objectList;

    private int id;
    private List<CommentBean.DataBean.CommentsBean> commentsBeanList;

    private ListTopContract.IListTopPresenter iListTopPresenter;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null){
            id = (int) bundle.getSerializable("itemId");
        }

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_comment, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        objectList = new ArrayList<>();
        rv_comment_talk = (RecyclerView) view.findViewById(R.id.rv_comment_talk);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        objectList.clear();
        startMVP();
        initRecyclerView();
    }

    private void startMVP() {
        iListTopPresenter = new ListTopPresenter(this);
        iListTopPresenter.getCommentData(id);
    }

    private void initRecyclerView() {
        commentRecyclerViewAdapter = new CommentRecyclerViewAdapter(mContext, objectList);
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        rv_comment_talk.setLayoutManager(layoutManager);
        rv_comment_talk.setAdapter(commentRecyclerViewAdapter);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void showProgress() {

    }

    @Override
    public void hideProgress() {

    }

    @Override
    public void showErrorInfo(String msg) {

    }

    @Override
    public void getEveryDayData(EveryDayBean everyDayBean) {

    }

    @Override
    public void getMayBeLikeData(MayBeLikeBean mayBeLikeBean) {

    }

    @Override
    public void getCommentData(CommentBean commentBean) {
        commentsBeanList = commentBean.getData().getComments();
        objectList.addAll(commentsBeanList);
        commentRecyclerViewAdapter.notifyDataSetChanged();
    }

    @Override
    public void getSingleProductData(SingleProductBean singleProductBean) {

    }
}
